package com.yunhe.device.controller.base;

import com.yunhe.common.exception.ArgumentErrorException;
import com.yunhe.common.exception.ObjectNotFoundException;
import com.yunhe.common.exception.UniqueConstraintsException;
import com.yunhe.common.model.ResultObject;
import com.yunhe.device.domain.base.EquipmentAttributes;
import com.yunhe.device.model.base.EquipmentAttributesQueryCondition;
import com.yunhe.device.model.base.EquipmentAttributesVo;
import com.yunhe.device.model.base.StatusVo;
import com.yunhe.device.service.base.EquipmentAttributeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import com.yunhe.common.util.CollectionUtil;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName EquipmentAttributesController
 * @Description TODO
 * @Author HeTao
 * @Date 2021/7/15 12:34
 * @Version 1.0
 **/
@Api(value = "EquipmentAttributes", description = "设备属性维护", tags = {"Base_EquipmentAttributes"})
@RestController
@RequestMapping("/attributes/equipmentAttributes")
public class EquipmentAttributesController {

    @Autowired
    private EquipmentAttributeService equipmentAttributeService;

    /**
     * 新增设备属性
     * @param equipmentAttributes 设备属性对象
     */
    @ApiOperation("新增设备属性")
    @RequestMapping(method = RequestMethod.POST)
    public ResultObject<EquipmentAttributes> createEquipmentAttributes(@RequestBody EquipmentAttributes equipmentAttributes)
            throws ArgumentErrorException, UniqueConstraintsException, ObjectNotFoundException {
        EquipmentAttributes newEquipmentAttributes = equipmentAttributeService.createEquipmentAttributes(equipmentAttributes);
        return new ResultObject<>(newEquipmentAttributes);
    }

    /**
     * 查询设备属性列表
     * @param equipmentAttributesQueryCondition 设备属性对象
     */
    @ApiOperation("查询设备属性列表")
    @RequestMapping(value = "/getEquipmentAttributesByCondition",method = RequestMethod.POST)
    public ResultObject<List<EquipmentAttributesVo>> getEquipmentAttributesByCondition(@RequestBody EquipmentAttributesQueryCondition equipmentAttributesQueryCondition) {
        Iterable<EquipmentAttributesVo> results  = equipmentAttributeService.getEquipmentAttributesByCondition(equipmentAttributesQueryCondition);
        return new ResultObject(results);
    }

    /**
     * 查询设备属性列表
     * @param id 设备属性对象
     */
    @ApiOperation("查询设备属性详情")
    @RequestMapping(value = "/getEquipmentAttributesById",method = RequestMethod.GET)
    public ResultObject<EquipmentAttributesVo> getEquipmentAttributesById(@ApiParam(value = "id",required = true) @RequestParam(value = "id") Long id) throws ObjectNotFoundException {
        EquipmentAttributesVo EquipmentAttributesVo = equipmentAttributeService.getEquipmentAttributesById(id);
        return new ResultObject<>(EquipmentAttributesVo);
    }

    /**
     * 根据id删除设备属性
     * @param id 设备属性对象
     */
    @ApiOperation("根据id删除设备属性")
    @RequestMapping(value = "/deleteEquipmentAttributesById",method = RequestMethod.POST)
    public ResultObject<Void> deleteEquipmentAttributesById(@ApiParam(value = "id",required = true) @RequestParam(value = "id") Long id) throws ArgumentErrorException, ObjectNotFoundException {
        equipmentAttributeService.deleteEquipmentAttributesById(id);
        return new ResultObject<>();
    }

    /**
     * 修改设备属性信息
     * @param equipmentAttributes 设备属性对象
     */
    @ApiOperation("修改设备属性信息")
    @PostMapping(value = "/updateEquipmentAttributes")
    public ResultObject<EquipmentAttributes> updateEquipmentAttributes(@RequestBody EquipmentAttributes equipmentAttributes) throws ArgumentErrorException, UniqueConstraintsException, ObjectNotFoundException {
        EquipmentAttributes newEquipmentAttributes = equipmentAttributeService.updateEquipmentAttributes(equipmentAttributes);
        return new ResultObject<>(newEquipmentAttributes);
    }

    /**
     * 设备属性禁用恢复
     * @param statusVo 设备属性对象
     */
    @ApiOperation("设备属性禁用恢复")
    @PostMapping(value = "/updateEquipmentAttributesStauts")
    public ResultObject<Void> updateEquipmentAttributesStauts(@RequestBody StatusVo statusVo) throws ArgumentErrorException, UniqueConstraintsException, ObjectNotFoundException {
        equipmentAttributeService.updateEquipmentAttributesStauts(statusVo);
        return new ResultObject<>();
    }

    /**
     * 根据设备类型查询设备属性列表
     * @param equipTypeName 设备属性对象
     */
    @ApiOperation("根据设备类型查询设备属性列表")
    @GetMapping (value = "/getEquipmentAttributesByEquipTypeName")
    public ResultObject<List<EquipmentAttributes>> getEquipmentAttributesByEquipTypeName(@ApiParam(value = "equipTypeName",required = false)
                                                                 @RequestParam(value = "equipTypeName",required = false) String equipTypeName) throws ArgumentErrorException, UniqueConstraintsException, ObjectNotFoundException {
        List<EquipmentAttributes> newEquipmentAttributess = equipmentAttributeService.getEquipmentAttributesByEquipTypeName(equipTypeName);
//        if(!CollectionUtil.isEmpty(newEquipmentAttributess)){
//            for (EquipmentAttributes equipmentAttributess : newEquipmentAttributess) {
//                equipmentAttributess.setType("01");
//            }
//        }
        return new ResultObject<>(newEquipmentAttributess);
    }
}
